package com.seeyon.apps.wangtuoplugin.controller;

import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.authenticate.domain.User;
import com.seeyon.ctp.common.controller.BaseController;
import com.seeyon.ctp.util.json.JSONUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.songjian.utils.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class URLController extends BaseController {

    private static final Log logger = LogFactory.getLog(URLController.class);


    //http://ip:port/mobplus/ZYOALogin?usercode=**&ts=**&client_id=**&security=**
    //usercode = 用户编码（手机号）
    //ts = 当前系统加签日期(例如2022-09-01)
    //client_id = 固定值(TestThird)
    //security = SHA-256加密值，加密规则：
    // sha256(usercode + ts + "oabipAa123")
    @Override
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String tourl = "http://36.133.169.150:5200/api/ssologin?code=";
//        User currentUser = AppContext.getCurrentUser();
//        String usercode = currentUser.getLoginName();
//        if (StringUtils.isBlank(usercode)) {
//            logger.info("获取用户编码（手机号）为空");
//            return null;
//        }
        String code = "18260622253";
        String callBackUrl = "http://36.133.169.150:5200/platform/runtime/sys/web/index.html#/main";
        Map<String,Object> str=new HashMap<String,Object>();
        str.put("code", code);
        str.put("callBackUrl", callBackUrl);
        String jsonString = JSONUtil.toJSONString(str);
        jsonString = URLEncoder.encode(jsonString);
        tourl += jsonString;
        response.sendRedirect(tourl);
        return null;
    }

}
